package PTA.javaA;

import java.util.Scanner;

public class ex18 {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        Shape shape[] = new Shape[n];
        for(int i=0;i<n;i++){
        String line = sc.next();
        if(line.equals("rect")){
            int width = sc.nextInt();
            int length = sc.nextInt();
shape[i] = new Rectangl(width,length);
        }else if(line.equals("cir")){
            int radius = sc.nextInt();
  shape[i]=new Circl(radius);
        }

    }
        System.out.println(sumAllPerimeter(shape));
        System.out.println(sumAllArea(shape));

        String temp = "[";
        for (int i = 0; i < n; i++) {
            temp += shape[i];
            temp += (i < n-1) ? ", " : "]";
        }
        System.out.println(temp);

        for (Shape i : shape) {
            System.out.println(i.getClass()+","+i.getClass().getSuperclass());
        }
    }

    static double sumAllPerimeter(Shape[] shape) {
        double sum = 0.0;
        for (Shape i : shape) {
            sum += i.getPerimeter();
        }
        return sum;
    }

    static double sumAllArea(Shape[] shape) {
        double sum = 0.0;
        for (Shape i : shape) {
            sum += i.getArea();
        }
        return sum;
    }

    }
   abstract class Shape{
    //.定义抽象类Shape
    //属性：不可变静态常量double PI，值为3.14，
    //抽象方法:public double getPerimeter(),public double getArea()
final static double PI=3.14;
       public abstract double getPerimeter();
       public abstract double getArea();
}
class Rectangl extends Shape{
int width;
int length;
Rectangl(int width,int length){
    this.width=width;
    this.length=length;
}
    @Override
    public double getPerimeter() {
        return (width+length)*2.0;
    }

    @Override
    public double getArea() {
        return width*length;
    }

    @Override
    public String toString() {
        return "Rectangle [" + "width=" + width + ", length=" + length + ']';
    }
}
class Circl extends  Shape{
    int radius;
    Circl(int radius){
        this.radius=radius;
    }
    @Override
    public double getArea() {
        return PI*radius*radius;
    }

    @Override
    public double getPerimeter() {
        return 2*PI*radius;
    }

    @Override
    public String toString() {
        return "Circle [" + "radius=" + radius + ']';
    }
}